define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'goods/goods/index',
                    add_url: 'goods/goods/add',
                    edit_url: 'goods/goods/edit',
                    del_url: 'goods/goods/del',
                    multi_url: 'goods/goods/multi',
                    table: 'goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                commonSearch: false, //是否启用通用搜索
                showExport: false,
                showToggle: false,
                showColumns: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                       /* {field: 'goods_common_id', title: __('Goods_common_id')},*/
                        {field: 'goods_name', title: __('Goods_name')},
                        {field: 'goods_jingle', title: __('Goods_jingle')},
                      //  {field: 'attr_value_ids', title: __('规格值')},
                      /*  {field: 'store_id', title: __('Store_id')},*/
                        {field: 'store_name', title: __('Store_name')},
                        {field: 'classes.names', title: __('Classes_id')},
                        {field: 'goods_price', title: __('Goods_price'), operate:'BETWEEN'},
                        {field: 'discount_price', title: __('Discount_price'), operate:'BETWEEN'},
                        {field: 'storage', title: __('Storage')},
                        /*{field: 'sale', title: __('Sale')},*/
                        {field: 'goods_image', title: __('Goods_image'), formatter: Table.api.formatter.image},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')},visible:false},
                        {field: 'status_text', title: __('Status'),operate:false},
                        {field: 'reason', title: __('Reason')},
                        {field: 'goods_verify', title: __('Goods_verify'), searchList: {"1":__('Goods_verify 1'),"2":__('Goods_verify 2'),"3":__('Goods_verify 3')}, formatter: Table.api.formatter.normal,visible:false},
                        {field: 'goods_verify_text', title: __('Goods_verify'), operate:false,searchList: {"1":__('Goods_verify 1'),"2":__('Goods_verify 2'),"3":__('Goods_verify 3')}, formatter: Table.api.formatter.normal},

                        {field: 'goods_verifyremark', title: __('Goods_verifyremark')},
                        {field: 'goods_commend', title: __('Goods_commend'), visible:false,searchList: {"1":__('Goods_commend 1'),"2":__('Goods_commend 2')}, formatter: Table.api.formatter.normal},
                        {field: 'goods_commend_text', title: __('Goods_commend'),operate:false, searchList: {"1":__('Goods_commend 1'),"2":__('Goods_commend 2')}, formatter: Table.api.formatter.normal},
                        {field: 'source', title: __('Source'), visible:false,searchList: {"1":__('Source 1'),"2":__('Source 2')}, formatter: Table.api.formatter.normal},
                        {field: 'source_text', title: __('Source'), operate:false,searchList: {"1":__('Source 1'),"2":__('Source 2')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange'},
                       /* {field: 'deletetime', title: __('Deletetime'), operate:'RANGE', addclass:'datetimerange'},*/
                        {field: 'operate', title: __('Operate'), table: table,events: Table.api.events.operate, formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                // $(table).data("operate-edit", null);
                                $(table).data("operate-del", null);
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            }}
                    ]
                ]
            });

            

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});